/*
 * @Description: 定义统一的用于返回数据时的方法
 * @Author: pinus
 * @Email: pinus0716@163.com
 * @Git: https://gitee.com/xyf97
 * @Date: 2021-10-06 21:09:46
 * @LastEditTime: 2021-10-08 15:03:47
 */
module.exports = function (req, res, next) {
  res.sendResult = function (data, code, msg) {
    // req.query url中参数解析得到的对象
    console.log(msg)
    const fmt = req.query.fmt ? fmt : 'rest'
    if (fmt === 'rest') {
      res.json({
        data: data,
        meta: {
          msg: msg,
          status: code
        }
      })
    }
  }
  next()
}
